#include<iostream>
using namespace std;
void Tway_Sort(int arr[], int n)
{
	int temp[1010];
	int head, tail;
	head = tail = 0;
	for (int i = 1; i < n; i++) {
		temp[0] = arr[0];
		if (temp[head] > arr[i]) {
			head = (head - 1 + n) % n;
			temp[head] = arr[i];
		}
		else if (temp[tail] < arr[i]) {
			tail = (tail + 1 + n) % n;
			temp[tail] = arr[i];
		}
		else {
			tail++;
			temp[tail] = temp[tail - 1];
			int j = 0;
			for (j = tail - 1; arr[j] < temp[(j - 1 + n ) % n]; j = (j-1+n)%n) {
				temp[j] = temp[(j - 1 + n) % n];
			}
			temp[j] = arr[i];
		}
     }
	for (int i = 0; i < n; i++) {
		arr[i] = temp[head];
		head = (head + 1 + n) % n;
	}
}
int main()
{
	int n;
	cin >> n;
	int arr[1010];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	Tway_Sort(arr, n);
	for (int i = 0; i < n; i++) {
		cout << arr[i] << " ";
	}
	return 0;
}